#include <iostream>
#include <map>
#include <cmath>

using namespace std;

const int N = 100010;

map<int, int> q;

int res;
int n,k;
void solve(){

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j ++)
            if(i != j && abs(i-j) <=k && (q[i] == j||q[j] ==i ))
            {
            res ++;
            cout<<i << " " << j<<endl;
            }
    }
}
int main(){
    cin >> n>> k;
    for(int i = 0; i<n; i++)
    {
        int a,b;
        cin >>a >> b;
        
        q[a] = b;

        

    }
    solve();
    cout << res;
    return 0;
}